/*
 * Copyright (c) 2002-2017 Huha City Group Holding Limited. All rights reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package me.huha.zhime.utils;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * @Title: Util
 * @Author: Yepx
 * @mail: yepx2013@gmail.com
 * @CreateTime: 2017年10月25日 下午1:49:21
 * @Todo: TODO
 */
public class Util {
	
	 /**
     * 获取当前日期时间 hh-12小时制 HH-24小时制，如果date为null则返回当前时间
     * 
     * @param formatModel
     * @param date
     * @return
     */
    public static String date2str(int formatModel, Date date) {
        SimpleDateFormat format = null;
        if (1 == formatModel) {
            format = new SimpleDateFormat("yyyy年MM月dd日");
        } else if (2 == formatModel) {
            format = new SimpleDateFormat("yyyy年MM月dd日 hh时mm分ss秒");
        } else if (3 == formatModel) {
            format = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
        } else if (4 == formatModel) {
            format = new SimpleDateFormat("yyyy年MM月dd日 hh时mm分ss秒SSS毫秒");
        } else if (5 == formatModel) {
            format = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒SSS毫秒");
        } else if (6 == formatModel) {
            format = new SimpleDateFormat("yyyy-MM-dd");
        } else if (7 == formatModel) {
            format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        } else if (8 == formatModel) {
            format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        } else if (9 == formatModel) {
            format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss:SSS");
        } else if (10 == formatModel) {
            format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
        } else if (11 == formatModel) {
            format = new SimpleDateFormat("yyyy/MM/dd");
        } else if (12 == formatModel) {
            format = new SimpleDateFormat("yyyy/MM/dd hh/mm/ss");
        } else if (13 == formatModel) {
            format = new SimpleDateFormat("yyyy/MM/dd HH/mm/ss");
        } else if (14 == formatModel) {
            format = new SimpleDateFormat("yyyy/MM/dd hh/mm/ss/SSS");
        } else if (15 == formatModel) {
            format = new SimpleDateFormat("yyyy/MM/dd HH/mm/ss/SSS");
        } else if (16 == formatModel) {
            format = new SimpleDateFormat("yyyyMMdd");
        } else if (17 == formatModel) {
            format = new SimpleDateFormat("yyyyMMddhhmmss");
        } else if (18 == formatModel) {
            format = new SimpleDateFormat("yyyyMMddHHmmss");
        } else if (19 == formatModel) {
            format = new SimpleDateFormat("yyyyMMddhhmmssSSS");
        } else if (20 == formatModel) {
            format = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        } else if (21 == formatModel) {
            format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        } else if (22 == formatModel) {
            format = new SimpleDateFormat("yyyy.MM.dd");
        } else {
            return null;
        }
        if (date == null) {
            date = new Date();
        }
        return format.format(date);
    }
    /**
     * 获取32位UUID
     */
    public static String getUUID() {
        String uuid = UUID.randomUUID().toString();
        uuid = uuid.replaceAll("-", "");
        return uuid;
    }
    
    /**
     * 金额（单位为分）格式化
     * @return
     */
    public static String orderAmountFormatting(Integer orderAmount){
    	
    	 DecimalFormat decimalFormat = new DecimalFormat("#0.00");
    	 
    	 double double_ = Double.parseDouble(Integer.toString(orderAmount));
    	 double_ = DoubleUtils.div(double_, 100d, 2);
    	 
    	 String money = decimalFormat.format(double_);
    	 
    	 return money;
    }
}
